package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsBrandMapper;
import com.qf.pojo.DtsBrand;
import com.qf.service.DtsBrandService;
import com.qf.vo.CatVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * @author Cc
 * @version 1.0
 */
@Service
public class DtsBrandServiceImpl implements DtsBrandService {
    @Autowired
    private DtsBrandMapper dtsBrandMapper;

    @Override
    public IPage<DtsBrand> querySelective(Integer page, Integer limit, String sort, String order) {
        return dtsBrandMapper.selectPage(new Page<>(page, limit),
                new QueryWrapper<DtsBrand>()
                        .eq("deleted",false)
                        .orderBy(!StringUtils.isEmpty(sort), "ASC".equalsIgnoreCase(order), sort));
    }

    @Override
    public List<CatVo> findIdAndUsername() {
        return dtsBrandMapper.find();
    }

    @Override
    public List<CatVo> findcategory() {

        return dtsBrandMapper.findcategory();

    }

    @Override
    public List<CatVo> findchilder() {
        return dtsBrandMapper.findchilder();
    }

    @Override
    public void save(DtsBrand brand) {
        dtsBrandMapper.insert(brand);
    }

    @Override
    public void update(DtsBrand brand) {
        brand.setUpdateTime(new Date());
        dtsBrandMapper.updateById(brand);
    }

    @Override
    public void delete(Integer id) {
        dtsBrandMapper.deleteUpdateById(id);
    }


}
